package com.reds.backend.controller.checkController;

import com.alibaba.fastjson2.JSONObject;
import com.reds.backend.utils.adminUtils.admin.StpAdminUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.reds.backend.service.check.checkShowService;

import java.util.Map;

@RestController
@RequestMapping("/check")
public class checkShowController {
    @Autowired
    checkShowService checkShowService;

    @PostMapping("/getArticle/")
    public String getArticle(@RequestParam Map<String,String> map){
        return checkShowService.getArticle(Integer.parseInt(map.get("id")));
    }

    @PostMapping("/showAllArticleByState/")
    public JSONObject checkShowService(@RequestParam Map<String,String> map){
        //StpAdminUtil.checkRoleOr("admin","superAdmin");
        int page =Integer.parseInt(map.get("page"));
        int sizes = Integer.parseInt(map.get("sizes"));
        return checkShowService.showAllArticleByState(map.get("state"),page,sizes);
    }
    @PostMapping("/showMyUncheck/")
    public JSONObject showMyUncheck(@RequestParam Map<String,String> map){
        StpAdminUtil.checkRoleOr("admin","superAdmin");
        int page =Integer.parseInt(map.get("page"));
        int sizes = Integer.parseInt(map.get("sizes"));
        return checkShowService.showMyUncheck(map.get("author"),page,sizes);
    }
    @PostMapping("/showAllArticle/")
    public JSONObject showAllArticle(@RequestParam Map<String,String> map) {
        StpAdminUtil.checkRoleOr("admin","superAdmin");
        int page = Integer.parseInt(map.get("page"));
        int sizes = Integer.parseInt(map.get("sizes"));
        return checkShowService.showAll(page,sizes);
    }
}
